package com.ehotting.edsta.system.controller;

import com.ehotting.eaf.core.utils.poi.ExcelUtil;
import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.domain.AjaxResult;
import com.ehotting.eaf.core.web.page.TableDataInfo;
import com.ehotting.edsta.common.log.annotation.Log;
import com.ehotting.edsta.common.log.enums.BusinessType;
import com.ehotting.eaf.security.annotation.PreAuthorize;
import com.ehotting.eaf.core.domain.system.api.SysIp;
import com.ehotting.edsta.system.service.ISysIpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 黑名单ip管理Controller
 * 
 * @author edsta
 * @date 2023-05-09
 */
@RestController
@RequestMapping("/ip")
public class SysIpController extends BaseController
{
    @Autowired
    private ISysIpService sysIpService;

    /**
     * 查询黑名单ip管理列表
     */
    @PreAuthorize(hasPermi = "edsta:ip:list")
    @GetMapping("/list")
    public TableDataInfo list(SysIp sysIp)
    {
        startPage();
        List<SysIp> list = sysIpService.selectSysIpList(sysIp);
        return getDataTable(list);
    }

    /**
     * 导出黑名单ip管理列表
     */
    @PreAuthorize(hasPermi = "edsta:ip:export")
    @Log(title = "黑名单ip管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysIp sysIp) throws IOException
    {
        List<SysIp> list = sysIpService.selectSysIpList(sysIp);
        ExcelUtil<SysIp> util = new ExcelUtil<SysIp>(SysIp.class);
        util.exportExcel(response, list, "黑名单ip管理数据");
    }

    /**
     * 获取黑名单ip管理详细信息
     */
    @PreAuthorize(hasPermi = "edsta:ip:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysIpService.selectSysIpById(id));
    }

    /**
     * 新增黑名单ip管理
     */
    @PreAuthorize(hasPermi = "edsta:ip:add")
    @Log(title = "黑名单ip管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysIp sysIp)
    {
        return toAjax(sysIpService.insertSysIp(sysIp));
    }

    /**
     * 修改黑名单ip管理
     */
    @PreAuthorize(hasPermi = "edsta:ip:edit")
    @Log(title = "黑名单ip管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysIp sysIp)
    {
        return toAjax(sysIpService.updateSysIp(sysIp));
    }

    /**
     * 删除黑名单ip管理
     */
    @PreAuthorize(hasPermi = "edsta:ip:remove")
    @Log(title = "黑名单ip管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysIpService.deleteSysIpByIds(ids));
    }
}
